﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tetris
{
    public class Frame
    {
        const char VERTICALLINE = '║';
        const char HORIZONTALLINE = '═';
        const char UPLEFTCORNER = '╔';
        const char DOWNLEFTCORNER = '╚';
        const char UPRIGHTCORNER = '╗';
        const char RIGHTDOWNCORNER = '╝';

        public void SetFrame(int StartX, int StartY, int FinishX, int FinishY)
        {
            int startX = 0;
            int startY = 0;
            int finishX = 0;
            int finishY = 0;

            startX = StartX; startY = StartY;
            finishX = FinishX; finishY = FinishY;

            Console.CursorTop = startY;
            Console.CursorLeft = startX;
            Console.Write(UPLEFTCORNER);
            Console.CursorTop = startY;
            Console.CursorLeft = finishX; //14
            Console.Write(UPRIGHTCORNER);
            Console.CursorTop = finishY; //2
            Console.CursorLeft = startX;
            Console.Write(DOWNLEFTCORNER);
            Console.CursorTop = finishY; //2
            Console.CursorLeft = finishX; //14
            Console.Write(RIGHTDOWNCORNER);

            // Draw horizontal lines.
            for (int i = 0; i < (finishX - startX) - 1; i++)
            {
                Console.CursorTop = startY;
                Console.CursorLeft = startX + 1 + i;
                Console.Write(HORIZONTALLINE);

                Console.CursorTop = finishY;
                Console.CursorLeft = startX + 1 + i;
                Console.Write(HORIZONTALLINE);
            }

            // Draw vertical lines.
            for (int i = 0; i < (finishY - startY) - 1; i++)
            {
                Console.CursorTop = startY + 1 + i;
                Console.CursorLeft = startX;
                Console.Write(VERTICALLINE);

                Console.CursorTop = startY + 1 + i;
                Console.CursorLeft = finishX;
                Console.Write(VERTICALLINE);
            }
        }

        public void ClearFrame(int StartX, int StartY, int FinishX, int FinishY)
        {
            int startX = 0;
            int startY = 0;
            int finishX = 0;
            int finishY = 0;

            startX = StartX; startY = StartY;
            finishX = FinishX; finishY = FinishY;

            Console.CursorTop = startY;
            Console.CursorLeft = startX;
            Console.Write(" ");
            Console.CursorTop = startY;
            Console.CursorLeft = finishX; //14
            Console.Write(" ");
            Console.CursorTop = finishY; //2
            Console.CursorLeft = startX;
            Console.Write(" ");
            Console.CursorTop = finishY; //2
            Console.CursorLeft = finishX; //14
            Console.Write(" ");

            // Draw horizontal lines.
            for (int i = 0; i < (finishX - startX) - 1; i++)
            {
                Console.CursorTop = startY;
                Console.CursorLeft = startX + 1 + i;
                Console.Write(" ");

                Console.CursorTop = finishY;
                Console.CursorLeft = startX + 1 + i;
                Console.Write(" ");
            }

            // Draw vertical lines.
            for (int i = 0; i < (finishY - startY) - 1; i++)
            {
                Console.CursorTop = startY + 1 + i;
                Console.CursorLeft = startX;
                Console.Write(" ");

                Console.CursorTop = startY + 1 + i;
                Console.CursorLeft = finishX;
                Console.Write(" ");
            }
        }

    }
}
